/*
 * Copyright 2014 Semidata. All rights reserved.
 */
package com.semidata.rtd.engine.main;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author shewei@semidata.com, She Wei
 * 
 */
public class TestThread {

	public static void main(String[] args) {

		final ReentrantLock lock = new ReentrantLock();
		final Condition cond = lock.newCondition();

		Thread thread = new Thread(new Runnable() {

			@Override
			public void run() {

				while (true) {
					lock.lock();
					try {
						try {
							cond.await();
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					} finally {
						lock.unlock();
					}

				}

			}

		});

		thread.start();

		int i = 0;
		long start = System.nanoTime();
		while (thread.isAlive()) {

			thread.stop();
			i++;
		}
		System.out.println("stop thread ok, times = " + i + " time = "
		        + ((System.nanoTime() - start)/1000000.0));

	}

}
